package android.zhcs.myapplication;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.jetbrains.annotations.NotNull;

public class myimg extends androidx.appcompat.widget.AppCompatImageView {


    private float tx = 0.0f;
    private float ty = 0.0f;
    private float sf = 1.f;

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    }

    private ScaleGestureDetector scaleGestureDetector;
    private myimg.sl sl;

    public myimg(@NonNull @NotNull Context context, @Nullable @org.jetbrains.annotations.Nullable AttributeSet attrs) {
        super(context, attrs);
        scaleGestureDetector = new ScaleGestureDetector(context, new sl());
        sl = new sl();
    }

    public boolean onTouchEvent(MotionEvent event) {
        scaleGestureDetector.onTouchEvent(event);
//        sl.onTou
        return true;
    }

    private class GestureListener extends GestureDetector.SimpleOnGestureListener {

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            tx -= distanceX;
            ty -= distanceY;
            invalidate();
            return super.onScroll(e1, e2, distanceX, distanceY);
        }
    }

    private class sl extends ScaleGestureDetector.SimpleOnScaleGestureListener {
        @Override
        public boolean onScale(ScaleGestureDetector scaleGestureDetector) {
            sf *= scaleGestureDetector.getScaleFactor();
            sf = Math.max(0.1f,Math.min(sf,5.0f));
            return true;
        }
    }
}
